package com.example.administrator.pandanotes;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;

/**
 * Created by 于博 on 2018-07-13.
 * 书籍类列表适配器
 */

public class BookClassAdapter extends ArrayAdapter {
    private int resourceId;
    public BookClassAdapter(Context context, int resource, List BookClassList) {
        super(context, resource, BookClassList);
        resourceId = resource;
    }
        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            BookClass bookClass = (BookClass) getItem(position);
            View view = LayoutInflater.from(getContext()).inflate(resourceId,null);//实例化一个View对象
            ImageView imageView = (ImageView) view.findViewById(R.id.fruit_image);//获取该布局内的图片视图
            TextView textView = (TextView)view.findViewById(R.id.fruit_name);//获取该布局内的文本视图
            imageView.setImageResource(bookClass.getBook_class_imageId());              //为图片视图设置图片资源
            textView.setText(bookClass.getClass_name());                          //为文本视图设置文本资源
            return view;
        }
}
